import React, {useState, useContext, useReducer, createContext } from 'react'


export const ColorContext = createContext({});

export const UPDATE_COLOR = "UPDATE_COLOR"

const reducer = (state,action) => {
    switch(action.type) {
        case UPDATE_COLOR :
            return action.color
            default:
                return state
    }
}
export const Color = props => {
    const [color, dispatch] = useReducer(reducer, 'blue') //第二个参数表示的是传给reducer的初始值，
    return (
        <ColorContext.Provider value={{color,dispatch}}>
            {props.children}
        </ColorContext.Provider>
    )
}
